package com.xquant.common.engine.utils;

import cn.hutool.core.map.MapUtil;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Component
public class ParamCache {
    public static Map<String, String> paramMap = new HashMap<String, String>();



    @PostConstruct
    public void init() {
        //系统启动中。。。加载paramMap

    }

    @PreDestroy
    public void destroy() {
        //系统运行结束
    }

    public static Long getLong(String key) {
        return MapUtils.getLong(paramMap, key);
    }

    public static String getString(String key) {
        return MapUtils.getString(paramMap, key);
    }

    public static Boolean getBoolean(String key) {
        return MapUtils.getBoolean(paramMap, key);
    }

    public void updateCache(String key, String value) {
        if (paramMap.keySet().contains(key)) {
            paramMap.put(key, value);
        }
    }
}
